package com.songyuesheng.app.service.Impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songyuesheng.app.mapper.LogsMapper;
import com.songyuesheng.app.entity.Logs;
import com.songyuesheng.app.service.LogsService;
import com.songyuesheng.app.commom.Result;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogsServiceImpl extends ServiceImpl<LogsMapper, Logs> implements LogsService {
    @Resource
    private LogsMapper logsMapper;

    @Override
    public Result<?> delLog(Integer id) {
        int i = logsMapper.deleteById(id);
        return Result.success(i);
    }

    @Override
    public Result<?> delLogs(List<Integer> ids) {
        int i = logsMapper.deleteBatchIds(ids);
        return Result.success(i);
    }

    @Override
    public Result<?> selectLogByPage(Integer pageNum, Integer pageSize, String operation, String type, String user) {
        LambdaQueryWrapper<Logs> queryWrapper = new LambdaQueryWrapper<Logs>().orderByAsc(Logs::getId);
        queryWrapper.like(StrUtil.isNotBlank(operation), Logs::getOperation, operation);
        queryWrapper.like(StrUtil.isNotBlank(type), Logs::getType, type);
        queryWrapper.like(StrUtil.isNotBlank(user), Logs::getUser, user);
        Page<Logs> page = new Page<>(pageNum, pageSize);
        Page<Logs> logsPage = logsMapper.selectPage(page, queryWrapper);
        return Result.success(logsPage);
    }
}
